package com.hanhan.chargingpile.stations.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hanhan.chargingpile.stations.pojo.entity.ChargingStations;
import com.hanhan.chargingpile.stations.pojo.vo.ChargingStationsVO;
import com.hanhan.chargingpile.stations.service.ChargingStationsService;
import com.hanhan.common.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 充电站 前端控制器
 * </p>
 *
 * @author HanHan
 * @since 2023-03-22
 */
@Api(tags = "充电站点管理")
@RestController
@RequestMapping("/admin/stations/chargingStations")
public class ChargingStationsController {

    @Resource
    private ChargingStationsService chargingStationsService;

    @ApiOperation("获取充电站点分页列表")
    @GetMapping("/list/{page}/{limit}")
    public R listPage(
            @ApiParam(value = "当前页码", required = true)
            @PathVariable Integer page,

            @ApiParam(value = "每页记录数", required = true)
            @PathVariable Integer limit,

            @ApiParam(value = "站点名称")
            @RequestParam(required = false) String stationName,
            @ApiParam(value = "省")
            @RequestParam(required = false) String province,
            @ApiParam(value = "市")
            @RequestParam(required = false) String city) {
        ChargingStations chargingStations = new ChargingStations();
        chargingStations.setStationName(stationName);
        chargingStations.setProvince(province);
        chargingStations.setCity(city);
        Page<ChargingStations> pageParam = new Page<>(page, limit);
        IPage<ChargingStationsVO> pageModel = chargingStationsService.selectChargingStationsList(pageParam, chargingStations);
        return R.ok().data("pageModel", pageModel);
    }

    @ApiOperation("获取站点详情信息")
    @GetMapping("/show/{id}")
    public R show(
            @ApiParam(value = "查询ID", required = true)
            @PathVariable Long id) {
        ChargingStationsVO data = chargingStationsService.show(id);
        return R.ok().data("data",data);
    }
}

